<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<%
if not CheckFlag(session("aaPostFlag"),1) then call JumpErrorPage(2)
if trim(SafeRequest("export",0))="xls" then
	Response.AddHeader "Content-type","application/vnd.ms-excel"
	Response.AddHeader "Content-Disposition","attachment; filename=excel.xls"
end if
%>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>报关单登记系统</title>
<!--#include file="lib/js-jquery-lib.asp"-->
<script type="text/javascript" src="lib/jquery.printElement.min.js"></script>
<script type="text/javascript">
	$(function() {
	/*
		// set portrait orientation
		//jsPrintSetup.setOption('orientation', jsPrintSetup.kPortraitOrientation);
		jsPrintSetup.setOption('orientation', jsPrintSetup.kLandscapeOrientation);
		// set top margins in millimeters
		jsPrintSetup.setOption('marginTop', 15);
		jsPrintSetup.setOption('marginBottom', 15);
		jsPrintSetup.setOption('marginLeft', 10);
		jsPrintSetup.setOption('marginRight', 10);
		// set page header
		jsPrintSetup.setOption('headerStrLeft', '');
		jsPrintSetup.setOption('headerStrCenter', '');
		jsPrintSetup.setOption('headerStrRight', '');
		// set empty page footer
		jsPrintSetup.setOption('footerStrLeft', '');
		jsPrintSetup.setOption('footerStrCenter', '&PT');
		jsPrintSetup.setOption('footerStrRight', '');
		jsPrintSetup.setOption('shrinkToFit', 1);
		jsPrintSetup.setOption('paperData','DMPAPER_A4');
		// clears user preferences always silent print value
		// to enable using 'printSilent' option
		jsPrintSetup.clearSilentPrint();
		// Suppress print dialog (for this context only)
		jsPrintSetup.setOption('printSilent', 1);
		// Do Print 
		// When print is submitted it is executed asynchronous and
		// script flow continues after print independently of completetion of print process! 
		//jsPrintSetup.print();
		// next commands

	*/
	
		$('body').printElement();
	});
</script>
<!--#include file="lib/js-google-analytics.asp"-->
</head>
<%

'获取提交查询的参数，和search_main一样
tx_search=trim(SafeRequest("tx_search",0))
wtr=trim(SafeRequest("wtr",1))
bwtr=trim(SafeRequest("bwtr",1))
category=trim(SafeRequest("category",1))
cd_status=trim(SafeRequest("cd_status",1))
fee=trim(SafeRequest("fee",0))
passno=trim(SafeRequest("passno",0))
orderno=trim(SafeRequest("orderno",0))
boxno=trim(SafeRequest("boxno",0))
ksrq=trim(SafeRequest("ksrq",0))
if ksrq<>"" then ksrq=cdate(ksrq)
jsrq=trim(SafeRequest("jsrq",0))
if jsrq<>"" then jsrq=cdate(jsrq)
jsksrq=trim(SafeRequest("jsksrq",0))
if jsksrq<>"" then jsksrq=cdate(jsksrq)
jsjsrq=trim(SafeRequest("jsjsrq",0))
if jsjsrq<>"" then jsjsrq=cdate(jsjsrq)
ytksrq=trim(SafeRequest("ytksrq",0))
if ytksrq<>"" then ytksrq=cdate(ytksrq)
ytjsrq=trim(SafeRequest("ytjsrq",0))
if ytjsrq<>"" then ytjsrq=cdate(ytjsrq)
cd_received=trim(SafeRequest("cd_received",0))
cd_paid=trim(SafeRequest("cd_paid",0))
cd_confirm=trim(SafeRequest("cd_confirm",0))
cd_check=trim(SafeRequest("cd_check",0))
post=SafeRequest("post",1)
detail=SafeRequest("detail",1)
search_count=trim(SafeRequest("search_count",1))
'额外打印需要的参数
print_title=trim(SafeRequest("print_title",0))
search_col=saferequest("search_col",0)
'response.write(search_col)

cd_synmode=SafeRequest("cd_synmode",1)
cd_source=SafeRequest("cd_source",1)
duplicate=trim(SafeRequest("duplicate",0))
dept=trim(SafeRequest("dept",1))
ic=trim(SafeRequest("ic",0))

'需要打印的列
dim sum()
aCol=split(search_col,", ")
redim sum(ubound(aCol))
'用来存储要进行合计的数组
for iLoop=0 to ubound(aCol)
	'response.write(aCol(iLoop))
next


'组合sql查询字符串，和search_main一样
'sql="select * from cdfee where true "
sql="select "
if search_count<>0 then sql=sql&" top "&search_count
sql=sql&" * from cdfee where true "
if tx_search<>"" then
	if len(tx_search)=18 and IsNumeric(tx_search) then
		'如果是18位的报关单号，直接查询。用于扫描枪的使用，提高搜索速度
		sql=sql&" and cd_no='"&tx_search&"'"
	else
		sql=sql&" and (cd_no like '%"&tx_search&"%' or cd_company like '%"&tx_search&"%' or cd_voyage like '%"&tx_search&"%' or cd_lading like '%"&tx_search&"%' or cd_verify like '%"&tx_search&"%' or cd_passno like '%"&tx_search&"%' or cd_orderno like '%"&tx_search&"%' or cd_boxno like '%"&tx_search&"%' or cd_memo like '%"&tx_search&"%')"
	end if
end if
if wtr<>0 then sql=sql&" and wtr="&wtr
if bwtr<>0 then sql=sql&" and bwtr="&bwtr
if category<>0 then sql=sql&" and category="&category
if cd_status<>0 then sql=sql&" and cd_status="&cd_status
if ksrq<>"" and jsrq<>"" then	sql=sql&" and (cd_date>=#"&ksrq&"# and cd_date<=#"&jsrq&"#)"
if jsksrq<>"" and jsjsrq<>"" then	sql=sql&" and (cd_settledate>=#"&jsksrq&"# and cd_settledate<=#"&jsjsrq&"#)"
if ytksrq<>"" and ytjsrq<>"" then	sql=sql&" and (cd_statusdate>=#"&ytksrq&"# and cd_statusdate<=#"&ytjsrq&"#)"
if cd_received<>"" then sql=sql&" and cd_received="&cd_received
if cd_paid<>"" then sql=sql&" and cd_paid="&cd_paid
if cd_confirm<>"" then sql=sql&" and cd_confirm="&cd_confirm
if cd_check<>"" then sql=sql&" and cd_check="&cd_check
if post=0 then
'如果不选择要查询的岗位，则查询该用户所有的有查询权限的岗位
	sSearchPost=""
	for i=0 to ubound(session("aaPostFlag"),2)
		if session("aaPostFlag")(1,i)>=1 and session("aaPostFlag")(0,i)<>0 and session("aaPostFlag")(0,i)<>5 then
			sSearchPost=sSearchPost&session("aaPostFlag")(0,i)&","
		end if
	next
	if len(sSearchPost)>0 then
		sSearchPost=left(sSearchPost,len(sSearchPost)-1)
		sql=sql&" and cd_post in ("&sSearchPost&")"
	else
		sql=sql&" and cd_post=-1"
	end if
else
'如果选择了查询岗位，则只查询该岗位
	sql=sql&" and cd_post="&post
end if
'查询详细费用的类别，判断是否有该类别的费用产生，返回cd
if detail<>0 then
	set rs_detail=Server.CreateObject("ADODB.Recordset")
	sql_detail="select DISTINCT cd from feedetail where feecategory.id="&detail
	rs_detail.open sql_detail,conn,1,1
	if not rs_detail.eof then
		'如果找到该类别的详细费用，就组合字段
		detail_querystring=rs_detail.getstring(,,,",")
	else
		'如果没找到该类别的详细费用，就用0来查询
		detail_querystring="0"
	end if
	rs_detail.close
	set rs_detail=nothing
	sql=sql&" and id in ("&detail_querystring&")"
end if
if fee<>"" then
	if fee then	sql=sql&" and not isnull(cd)" else sql=sql&" and isnull(cd)"
end if
if passno<>"" then
	if passno then sql=sql&" and cd_passno<>''" else sql=sql&" and cd_passno=''"
end if
if orderno<>"" then
	if orderno then sql=sql&" and cd_orderno<>''" else sql=sql&" and cd_orderno=''"
end if
if boxno<>"" then
	if boxno then sql=sql&" and cd_boxno<>''" else sql=sql&" and cd_boxno=''"
end if

if cd_synmode<>0 then sql=sql&" and cd_synmode="&cd_synmode
if cd_source<>0 then sql=sql&" and cd_source="&cd_source

if duplicate<>"" then
    set rs_duplicate=Server.CreateObject("ADODB.Recordset")
    sql_duplicate="select cd_no from cd group by cd_no having count(cd_no)>1"
    rs_duplicate.open sql_duplicate,conn,1,1
    if not rs_duplicate.eof then
        duplicate_querystring=rs_duplicate.getstring(,,,"','")
        duplicate_querystring="'"&duplicate_querystring&"'"
    else
        duplicate_querystring="''"
    end if
    rs_duplicate.close
    set rs_duplicate=nothing
    if duplicate then
        sql=sql&" and cd_no in ("&duplicate_querystring&")"
    else
        sql=sql&" and cd_no not in ("&duplicate_querystring&")"
    end if
end if
if dept<>0 then
    set rs_ic_code=Server.CreateObject("ADODB.Recordset")
    sql_ic_code="select ic_code from bwtric,deptic where deptic.icid=bwtric.id and deptic.deptid="&dept
    rs_ic_code.open sql_ic_code,conn,1,1
    if not rs_ic_code.eof then
        ic_code_querystring=rs_ic_code.getstring(,,,"','")
        ic_code_querystring="'"&ic_code_querystring&"'"
    else
        ic_code_querystring="''"
    end if
    rs_ic_code.close
    set rs_ic_code=nothing
    sql=sql&" and ic_code in ("&ic_code_querystring&")"
end if
if ic<>"" then sql=sql&" and ic_code='"&ic&"'"

sql=sql&" order by cd_update desc,id desc"
'response.write sql
'response.end
'执行数据查询
set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
If rs.eof Then
	response.write("没有检索到数据!")
	response.end
' else
	' sql_sum="select sum(cd_receive) as sum_cd_receive,sum(cd_pay) as sum_cd_pay,sum(total_receive) as sum_total_receive,sum(total_pay) as sum_total_pay from("&sql&")"
	' set rs_sum = Server.CreateObject("ADODB.Recordset")
	' rs_sum.open sql_sum,conn,1,1
	' sum_cd_receive=rs_sum("sum_cd_receive")
	' sum_cd_pay=rs_sum("sum_cd_pay")
	' sum_total_receive=rs_sum("sum_total_receive")
	' sum_total_pay=rs_sum("sum_total_pay")
	' rs_sum.close
	' set rs_sum=nothing

End if
%>
<body style="font-size:10pt;font-family:宋体">
<div>
<h1 style="text-align:center"><%=print_title%></h1>
<table width="100%" border="1" style="border-collapse:collapse;">
	<thead>
		<tr>
			<th>序号</th>
			<%
				for iLoop=0 to ubound(aCol)
					response.write("<th scope='col'>"&d.item(aCol(iLoop))&"</th>")
				next
			%>
		</tr>
	</thead>
	<tbody>
<%
	do while not rs.eof
%>
		<tr>
			<td align="center"><%=rs.AbsolutePosition%></td>
			<%for iLoop=0 to ubound(aCol)%>
			<td <%if t.item(aCol(iLoop)) then response.write("align='center'")%>>
			<%
				select case aCol(iLoop)
					case "cd_no"
						'报关单号显示9位数字
                        if rs("cd_source")<>2 then
                            response.write(right(rs(aCol(iLoop)),9))
                        else
                            response.write(rs(aCol(iLoop)))
                        end if
					case "cy_receive","sj_receive","jk_receive","qt_receive","cy_pay","sj_pay","jk_pay","qt_pay"
						sql_fee="select sum("&right(aCol(iLoop),len(aCol(iLoop))-3)&") as "&aCol(iLoop)&" from feedetail where feecategory.short='"&left(aCol(iLoop),2)&"' and cd="&rs("id")
						'response.write(sql_fee)
						'response.end
						set rs_fee = Server.CreateObject("ADODB.Recordset")
						rs_fee.open sql_fee,conn,1,1
							if rs_fee(aCol(iLoop))<>"" then
								response.write(rs_fee(aCol(iLoop)))
							end if
						rs_fee.close
						set rs_fee=nothing
					case else
						response.write(rs(aCol(iLoop)))
						
				end select
			%>
			</td>
			<%next%>
		</tr>
<%
		rs.movenext
	loop
%>
		<tr>
			<th>合计</th>
			<%for iLoop=0 to ubound(aCol)%>
			<th scope='col'>
			<%
				if t.item(aCol(iLoop)) then
					'判断是否需要显示合计
					select case aCol(iLoop)
						case "cd_receive","cd_pay","cd_actreceive","cd_actpay","total_receive","total_pay"
							sql_sum="select sum("&aCol(iLoop)&") as sum_"&aCol(iLoop)&" from("&sql&")"
							set rs_sum = Server.CreateObject("ADODB.Recordset")
							rs_sum.open sql_sum,conn,1,1
							response.write(rs_sum("sum_"&aCol(iLoop)))
							rs_sum.close
							set rs_sum=nothing
						case "cy_receive","sj_receive","jk_receive","qt_receive","cy_pay","sj_pay","jk_pay","qt_pay"
							sql_sum="select sum("&right(aCol(iLoop),len(aCol(iLoop))-3)&") as "&aCol(iLoop)&" from ("&sql&") as dd left join feedetail on dd.id=feedetail.cd where feecategory.short='"&left(aCol(iLoop),2)&"'"
							set rs_sum = Server.CreateObject("ADODB.Recordset")
							rs_sum.open sql_sum,conn,1,1
							if rs_sum(aCol(iLoop))<>"" then
								response.write(rs_sum(aCol(iLoop)))
							else
								response.write("0")
							end if
							rs_sum.close
							set rs_sum=nothing
					end select
				end if
			%>
			</th>
			<%next%>
		</tr>
	</tbody>
</table>
<%
rs.close
Set rs=nothing
%>
</div>
</body>
</html>
<!--#include file="lib/connclose.asp"-->

